package com.cy.wenxinapi.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

/**
 * @author: c
 * @date: 2024/3/22 14:14
 * @description:
 */

@Component
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(factory);

        // 设置Key的序列化方式为String类型
        template.setKeySerializer(new StringRedisSerializer());

        // 设置Value的序列化方式（根据您的实际需求选择合适的序列化器）
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        return template;
    }

}
